package jee.boot.oauth.config.exception;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.common.exceptions.InvalidScopeException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.common.exceptions.UnsupportedGrantTypeException;

@JsonSerialize(using = CustomOauthExceptionSerializer.class)
public class CustomOauthException extends OAuth2Exception {

	private static final long serialVersionUID = 1L;
	private String cusMsg;

	public CustomOauthException(String msg, Throwable t) {
		super(msg, t);
		cusMsg=t.getMessage();
		if(t instanceof InvalidGrantException){
			cusMsg="无效的授权[grant]";
		}else if(t instanceof UnsupportedGrantTypeException){
			cusMsg="授权类型错误[grant_type]";
		}else if(t instanceof InvalidScopeException){
			cusMsg="授权范围错误[scope]";
		}
	}

	public CustomOauthException(String msg) {
		super(msg);
	}

	public String getCusMsg() {
		return cusMsg;
	}

	public void setCusMsg(String cusMsg) {
		this.cusMsg = cusMsg;
	}
}
